package com.kevin.design.creationalPattern.builder;

public class BuilderOfActor {
    public static void main(String[] args) {
//        Director director = new Director();
//        Actor actor = director.createActor(new HeroBuilder());
//        System.out.println(actor);

        // 简化
        Actor actor = Builder.create(new HeroBuilder());
        System.out.println(actor);
    }
}

class Actor{
    private String name;
    private String type;

    public Actor() {
    }

    public Actor(String name, String type) {
        this.name = name;
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return "Actor{" +
                "name='" + name + '\'' +
                ", type='" + type + '\'' +
                '}';
    }
}

abstract class Builder{
    Actor actor = new Actor();
    abstract void buildName();
    abstract void buildType();
    public Actor createActor(){
        return actor;
    }
    public static Actor create(Builder builder){
        builder.buildName();
        builder.buildType();
        return builder.createActor();
    }
}

class HeroBuilder extends Builder{

    @Override
    void buildName() {
        actor.setName("琦玉");
    }

    @Override
    void buildType() {
        actor.setType("hero");
    }
}

//class Director{
//    public Actor createActor(Builder builder){
//        builder.buildName();
//        builder.buildType();
//        return builder.createActor();
//    }
//}